/*
 * Copyright The Dragonfly Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package mgr

import (
	"context"

	"github.com/dragonflyoss/Dragonfly/apis/types"
)

// DfgetTaskMgr as an interface defines all operations against DfgetTask.
// A DfgetTask represents a download process initiated by dfget or other clients.
type DfgetTaskMgr interface {
	// Add a new dfgetTask, we use clientID and taskID to identify a dfgetTask uniquely.
	// ClientID should be generated by dfget, supernode will use it directly.
	// NOTE: We should create a new dfgetTask for each download process,
	//       even if the downloads initiated by the same machine.
	Add(ctx context.Context, dfgetTask *types.DfGetTask) error

	// Get a dfgetTask info with specified clientID and taskID.
	Get(ctx context.Context, clientID, taskID string) (dfgetTask *types.DfGetTask, err error)

	// GetCIDByPeerIDAndTaskID returns cid with specified peerID and taskID.
	GetCIDByPeerIDAndTaskID(ctx context.Context, peerID, taskID string) (string, error)

	// GetCIDsByTaskID returns cids as a string slice with specified taskID.
	GetCIDsByTaskID(ctx context.Context, taskID string) ([]string, error)

	// GetCIDAndTaskIDsByPeerID returns a cid<->taskID map by specified peerID.
	GetCIDAndTaskIDsByPeerID(ctx context.Context, peerID string) (map[string]string, error)

	// List returns the list of dfgetTask.
	List(ctx context.Context, filter map[string]string) (dfgetTaskList []*types.DfGetTask, err error)

	// Delete a dfgetTask with clientID and taskID.
	Delete(ctx context.Context, clientID, taskID string) error

	// UpdateStatus updates the status of dfgetTask with specified clientID and taskID.
	// Supernode will update the status of dfgetTask in the following situations:
	// 1. after init the dfgetTask
	// 2. when success/fail to download some pieces
	// 3. when the entire download process ends in success or failure
	UpdateStatus(ctx context.Context, clientID, taskID, status string) error
}
